package com.drojian.demo1.test5;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.drojian.demo.R;


public class ToastUtils {
    public static void showCustomToast(Context context, String message) {
        // 使用LayoutInflater加载自定义布局
        LayoutInflater inflater = LayoutInflater.from(context);
        View layout = inflater.inflate(R.layout.ui5_myself_toast, null);

        // 获取布局中的TextView并设置文本
        TextView textView = layout.findViewById(R.id.custom_toast_text1);
        textView.setText(message);

        // 创建并显示Toast
        Toast toast = new Toast(context);
        toast.setDuration(Toast.LENGTH_SHORT);
        // 设置Toast的位置，Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL为底部居中
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setView(layout);
        toast.show();
    }
}
